using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using MbUnit.Core.Framework;
using MbUnit.Framework;
using Doubler;
using Doubler.Templates.UnitTest;
using Doubler.Logging;
using TestAssistance;

namespace Test.UnitTestGenerator
{
    [TestFixture]
    public class TestUnitTestGenerator
    {
        [Test]
        public void GenerateUnitTestForOrder()
        {
            Reflector.Framework.ReflectorServices Services = ReflectorAssistant.ReflectorServices;
            Services.AssemblyManager.LoadFile(typeof(TestSubject.Order).Assembly.Location);
            Services.AssemblyManager.LoadFile(typeof(Object).Assembly.Location);
            Reflector.CodeModel.ITypeDeclaration SubjectType = Services.Search.FindType(typeof(TestSubject.Order));
            TestTemplate TestSubject = new TestTemplate(Refly.CodeDom.CodeLanguage.Cs, @"C:\Temp", SubjectType, Services);
            LogClassFactory.Logger.LogEvent += new LogEventHandler(LogMessage);
            TestSubject.TestFramework = TestFramework.MbUnit;
            TestSubject.WithTestAttibutes = true;
            TestSubject.OutputLanguage = Refly.CodeDom.CodeLanguage.Cs;
            TestSubject.Namespace = "Double";
            TestSubject.Generate();

            using (FileStream ActualStream = new FileStream(TestSubject.OutputFilePath, FileMode.Open))
            {
                using (Stream ExpectedStream = this.GetType().Assembly.GetManifestResourceStream("Test.UnitTestGenerator.TestOrder.Cs"))
                {
                    FileAssert.AreStreamContentEqual(ExpectedStream, ActualStream);
                }
            }
        }

        public void LogMessage(String message)
        {
            System.Diagnostics.Debug.WriteLine(message);
        }
    }
}
